home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_14.lha / 6_14 / tsta.c < prev    next >
Text File  |  1993-08-08  |  947b  |  29 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. include <stream.h>
  6. include "6_14a.c"
  7.  
  8. stream &operator<<(ostream &out, complex j)
  9.  return out << "(" << j.re << ", " << j.im << ")"; }
  10. nline complex complex::operator+(complex j) { complex x(re+j.re, im+j.im); return x; }
  11. nline complex complex::operator-(complex j) { complex x(re-j.re, im-j.im); return x; }
  12. nline complex complex::operator-() { complex x(-re, -im); return x; }
  13. nline complex complex::operator*(complex j) { complex x(re*j.re, im*j.im); return x; }
  14.  
  15. ain()
  16.  
  17.    complex i = 0.0, j = 1.0;
  18.    cout << "i= " << i << ", j=" << j << "\n";
  19.    i = j + 3.0;
  20.    cout << "i= " << i << ", j=" << j << "\n";
  21.    i = j - 3.0;
  22.    cout << "i= " << i << ", j=" << j << "\n";
  23.    i = -j;
  24.    cout << "i= " << i << ", j=" << j << "\n";
  25.    i = i * j;
  26.    cout << "i= " << i << ", j=" << j << "\n";
  27.    return 0;
  28.  
  29.